package scjp.preparation.concurrency.executor;

import java.util.concurrent.Executor;

class Task implements Runnable {

	@Override
	public void run() {
		System.out.println("Calling Task.run()");

	}

}

class RepeatedExecutor implements Executor {

	@Override
	public void execute(Runnable arg0) {
		new Thread(arg0).start();

	}

	public void execute(Runnable runnable, int times) {
		System.out.printf(
				"Calling Task.run() thro' Executor.execute() for %d times %n",
				times);
		for (int i = 0; i < times; i++) {
			execute(runnable);
		}
	}

}

class ExecutorTest {

	public static void main(String[] args) {
		Runnable runnable = new Task();
		System.out
				.println("Calling Task.run() by directly creating a Thread object");
		Thread thread = new Thread(runnable);
		thread.start();
		RepeatedExecutor executor = new RepeatedExecutor();
		executor.execute(runnable, 3);
	}
}
